package com.aoxin.service.impl.course.webCourse;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.aoxin.mapper.course.webCourse.SlfChildrenMapper;
import com.aoxin.mapper.course.webCourse.SlfClassChildrenMapper;
import com.aoxin.model.course.SlfChildren;
import com.aoxin.model.course.SlfClassChildren;
import com.aoxin.service.inter.course.webCourse.ClassChildrenService;
import com.aoxin.util.EmptyUtil;

@Service
public class ClassChildrenServiceImpl implements ClassChildrenService {


    @Autowired
    SlfClassChildrenMapper slfClassChildrenMapper;

    @Autowired
    SlfChildrenMapper slfChildrenMapper;

    @Override
    @Transactional
    public Integer insertClassChildren(SlfClassChildren slfClassChildren) throws IllegalAccessException {
        Integer result = 0;
        if(!EmptyUtil.objFieldsIsEmpty(slfClassChildren)){
            result = slfClassChildrenMapper.insertClassChildren(slfClassChildren);
        }
        return result;
    }

    @Override
    @Transactional
    public Integer updateClassChildren(SlfClassChildren slfClassChildren) throws IllegalAccessException {
        Integer result = 0;
        if(!EmptyUtil.objFieldsIsEmpty(slfClassChildren)){
            result = slfClassChildrenMapper.updateClassChildren(slfClassChildren);
        }
        return result;
    }

    @Override
    @Transactional
    public Integer deleteClassChildren(Integer classChildrenId) {
        Integer result = 0;
        if(classChildrenId != null){
            result = slfClassChildrenMapper.deleteClassChildren(classChildrenId);
        }
        return result;
    }

    @Override
    public List<SlfClassChildren> getClassChildren(SlfClassChildren slfClassChildren) {
        List<SlfClassChildren> slfClassChildrenList = slfClassChildrenMapper.getClassChildren(slfClassChildren);
        return slfClassChildrenList;
    }

    @Override
    @Transactional
    public Integer batchInsertClassChildren(Integer classId, List<Integer> childrenIds) {
        Integer result = 0;
        if(classId != null){
            if(childrenIds != null && childrenIds.size() > 0){
                result = slfClassChildrenMapper.batchInsertClassChildren(classId,childrenIds);
            }
        }
        return result;
    }

    @Override
    @Transactional
    public Integer batchDeleteClassChildren(Integer classId, List<Integer> childrenIds) {
        Integer result = 0;
        if(classId != null){
            if(childrenIds != null && childrenIds.size() > 0){
                result = slfClassChildrenMapper.batchDeleteClassChildren(classId,childrenIds);
            }
        }
        return result;
    }

    @Override
    public List<Integer> getChildrenIdList(Integer classId) {
        List<Integer> childrenList = new ArrayList<>();
        if(classId != null){
            childrenList = slfClassChildrenMapper.getChildrenIdList(classId);
        }
        return childrenList;
    }

    @Override
    public List<SlfChildren> getChildrenList(List<Integer> childrenList) {
        List<SlfChildren> slfChildrenList = new ArrayList<>();
        if(childrenList != null && childrenList.size() > 0){
            for(Integer childrenId : childrenList){
                slfChildrenList.add(slfChildrenMapper.getAChildren(childrenId));
            }
        }
        return slfChildrenList;
    }
}
